package com.hxzy.shop.config.oauth;


import com.hxzy.shop.dto.UserDto;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;

/**
 * 用户登录信息
 */
@Data
public class SecurityUser implements UserDetails, Serializable {
    private static final long serialVersionUID = 6555321999509986913L;

    /**
     * ID
     */
    private Long id;
    /**
     * 用户名
     */
    private String username;
    /**
     * 用户密码
     */
    private String password;
    /**
     * 用户状态
     */
    private Boolean enabled;
    /**
     * 登录客户端ID
     */
    private String clientId;

    private Long merchantId;
    private Long storeId;

    public SecurityUser() {
    }

    public SecurityUser(UserDto userDto) {
        this.setId(userDto.getId());
        this.setUsername(userDto.getUser_name());
        this.setPassword(userDto.getPassword());
        this.setEnabled(userDto.getState());
        this.setClientId(userDto.getClient_id());
        this.setMerchantId(userDto.getMerchantId());
        this.setStoreId(userDto.getStoreId());
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return this.enabled;
    }

}
